<?php
class Answer_Service_Callback extends Phpfox_Service {
    /**
     * get mess when get answer
     * @param array $aNotification
     * @return array
     */
    public function getNotificationQuestion_Answer($aNotification)
    {
        $sMessage =Phpfox::getService('notification')->getUsers($aNotification)." ". Phpfox::getPhrase('answer.answered_your_question');

        return array(
            'link' => Phpfox::getLib('url')->makeUrl('answer.question.view', array('id' => $aNotification['item_id'])),
            'message' => $sMessage,
            'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
        );
    }
    public function deleteLike() {

    }
    public function getNotificationAnswer_Correct($aNotification)
    {
        $sMessage =Phpfox::getService('notification')->getUsers($aNotification)." ". Phpfox::getPhrase('answer.choose_your_answer_is_correct');
        $aCondition = 'a.id = '. $aNotification['item_id'];
        $aAnswer = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        return array(
            'link' => Phpfox::getLib('url')->makeUrl('answer.question.view', array('id' => $aAnswer['data']['question_id'])),
            'message' => $sMessage,
            'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
        );
    }
    public function addLike($iItemId) {
        $iItemId = (int) $iItemId;
        $aCondition = array('q.id = '.$iItemId);
        $aQuestion = Phpfox::getService('answer.question')->getForEdit($aCondition);

        Phpfox::getService('notification.process')->add('answer_question_like' ,  $iItemId, $aQuestion['data']['user_id'] , Phpfox::getUserId());
    }
    public function addLikeAnswer($iItemId) {
        $iId = (int) $iItemId;
        $aCondition = 'a.id = '.$iId;
        $aAnswer = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        Phpfox::getService('notification.process')->add('answer_answer_like' ,  $iId, $aAnswer['data']['user_id'] , Phpfox::getUserId());
    }
    public function getNotificationQuestion_Like($aNotification)
    {
        $sMessage =Phpfox::getService('notification')->getUsers($aNotification)." ". Phpfox::getPhrase('answer.like_your_question');

        return array(
            'link' => Phpfox::getLib('url')->makeUrl('answer.question.view', array('id' => $aNotification['item_id'])),
            'message' => $sMessage,
            'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
        );
    }
    public function getNotificationAnswer_Like($aNotification)
    {
        $sMessage =Phpfox::getService('notification')->getUsers($aNotification)." ". Phpfox::getPhrase('answer.like_your_answer');
        $aCondition = 'a.id = '. $aNotification['item_id'];
        $aAnswer = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        return array(
            'link' => Phpfox::getLib('url')->makeUrl('answer.question.view', array('id' => $aAnswer['data']['question_id'])),
            'message' => $sMessage,
            'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
        );
    }

    public function getActivityFeedQuestion($aItem)
    {
        $aCondition = array('q.id = '. (int) $aItem['item_id']);
        $aRow = Phpfox::getService('answer.question')->getForEdit($aCondition);
        $aRow = $aRow['data'];


        $sLink = Phpfox::getLib('url')->makeUrl('answer.question.view',array('id' => (int) $aItem['item_id']));

        return array(
            'feed_title' => $aRow['title'],
            'feed_info' => Phpfox::getPhrase('answer.asked_a_question'),
            'feed_link' => $sLink,
            'feed_content' => $aRow['detail'],
            'feed_total_like' => 0,
            'feed_is_liked' => isset($aRow['is_liked']) ? $aRow['is_liked'] : false,
            'time_stamp' => $aItem['time_stamp'],
            'enable_like' => true,
            'like_type_id' => 'answer',
            'like_item_id' => $aRow['id']
        );
    }

    public function getActivityFeedAnswer($aItem)
    {
        $aCondition = 'a.id = '. (int) $aItem['item_id'];
        $aRow = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        $aRow = $aRow['data'];
        $sLink = Phpfox::getLib('url')->makeUrl('answer.question.view',array('id' => $aRow['question_id']));
        return array(
            'feed_title' => $aRow['question_title'],
            'feed_info' => Phpfox::getPhrase('answer.answer_a_question'),
            'feed_link' => $sLink,
            'feed_content' => $aRow['detail'],
            'feed_total_like' => 0,
            'feed_is_liked' => isset($aRow['is_liked']) ? $aRow['is_liked'] : false,
            'time_stamp' => $aItem['time_stamp'],
            'enable_like' => true,
            'like_type_id' => 'answer_answer',
            'like_item_id' => $aRow['id']
        );
    }
    public function getActivityFeedCorrect($aItem)
    {
        $aCondition = 'a.id = '. (int) $aItem['item_id'];
        $aRow = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        $aRow = $aRow['data'];


        $sLink = Phpfox::getLib('url')->makeUrl('answer.question.view',array('id' => $aRow['question_id']));

        return array(
            'feed_title' => $aRow['question_title'],
            'feed_info' => Phpfox::getPhrase('answer.choose_correct_answer'),
            'feed_link' => $sLink,
            'feed_content' => $aRow['detail'],
            'feed_total_like' => 0,
            'feed_is_liked' => isset($aRow['is_liked']) ? $aRow['is_liked'] : false,
            'time_stamp' => $aItem['time_stamp'],
            'enable_like' => true,
            'like_type_id' => 'answer_answer',
            'like_item_id' => $aRow['id']
        );
    }
    public function getActivityFeedVoteup($aItem)
    {
        $aCondition = 'a.id = '. (int) $aItem['item_id'];
        $aRow = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        $aRow = $aRow['data'];


        $sLink = Phpfox::getLib('url')->makeUrl('answer.question.view',array('id' => $aRow['question_id']));

        return array(
            'feed_title' => $aRow['question_title'],
            'feed_info' => Phpfox::getPhrase('answer.vote_up_a_answer'),
            'feed_link' => $sLink,
            'feed_content' => $aRow['detail'],
            'feed_total_like' => 0,
            'feed_is_liked' => isset($aRow['is_liked']) ? $aRow['is_liked'] : false,
            'time_stamp' => $aItem['time_stamp'],
            'enable_like' => true,
            'like_type_id' => 'answer_answer',
            'like_item_id' => $aRow['id']
        );
    }

    public function getActivityFeedVotedown($aItem)
    {
        $aCondition = 'a.id = '. (int) $aItem['item_id'];
        $aRow = Phpfox::getService('answer.answer')->getForEdit($aCondition);
        $aRow = $aRow['data'];


        $sLink = Phpfox::getLib('url')->makeUrl('answer.question.view',array('id' => $aRow['question_id']));

        return array(
            'feed_title' => $aRow['question_title'],
            'feed_info' => Phpfox::getPhrase('answer.vote_down_a_answer'),
            'feed_link' => $sLink,
            'feed_content' => $aRow['detail'],
            'feed_total_like' => 0,
            'feed_is_liked' => isset($aRow['is_liked']) ? $aRow['is_liked'] : false,
            'time_stamp' => $aItem['time_stamp'],
            'enable_like' => true,
            'like_type_id' => 'answer_answer',
            'like_item_id' => $aRow['id']
        );
    }
    public function getDashboardActivity()
    {
        $aUser = Phpfox::getService('user')->get(Phpfox::getUserId(), true);

        return array(
            Phpfox::getPhrase('answer.answers') => $aUser['activity_answers']
        );
    }
}